<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>from_excel (Table)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File ex.rb, line 58</span>
 <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">from_excel</span>(<span class="ruby-identifier">file</span>)
  <span class="ruby-constant">Spreadsheet</span>.<span class="ruby-identifier">client_encoding</span> = <span class="ruby-value str">'UTF-8'</span>
  <span class="ruby-identifier">book</span> = <span class="ruby-constant">Spreadsheet</span>.<span class="ruby-identifier">open</span> <span class="ruby-identifier">file</span>
  <span class="ruby-identifier">rbook</span>=<span class="ruby-constant">RBook</span><span class="ruby-operator">::</span><span class="ruby-identifier">new</span>
  <span class="ruby-identifier">book</span>.<span class="ruby-identifier">worksheets</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">sheet</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">t</span> = <span class="ruby-constant">RTable</span>.<span class="ruby-identifier">new</span>
    <span class="ruby-identifier">p</span> <span class="ruby-identifier">t</span>
    <span class="ruby-identifier">len</span> = []
    <span class="ruby-identifier">sheet</span>.<span class="ruby-identifier">each_with_index</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">row</span>,<span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
          <span class="ruby-identifier">trow</span> = <span class="ruby-identifier">t</span>.<span class="ruby-identifier">add_row</span>
        <span class="ruby-keyword kw">end</span>
      <span class="ruby-identifier">row</span>.<span class="ruby-identifier">each_with_index</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">col</span>,<span class="ruby-identifier">ind</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">len</span>[<span class="ruby-identifier">ind</span>]=<span class="ruby-value">0</span>
        <span class="ruby-identifier">str</span> = <span class="ruby-identifier">sheet</span>.<span class="ruby-identifier">cell</span>(<span class="ruby-identifier">i</span>,<span class="ruby-identifier">ind</span>).<span class="ruby-identifier">to_s</span>
        <span class="ruby-identifier">hash</span> = {
         <span class="ruby-identifier">:ul</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">row</span>.<span class="ruby-identifier">format</span>(<span class="ruby-identifier">ind</span>).<span class="ruby-identifier">font</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-value str">&quot;@underline&quot;</span>),
         <span class="ruby-identifier">:so</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">row</span>.<span class="ruby-identifier">format</span>(<span class="ruby-identifier">ind</span>).<span class="ruby-identifier">font</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-value str">&quot;@strikeout&quot;</span>),
         <span class="ruby-identifier">:weight</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">row</span>.<span class="ruby-identifier">format</span>(<span class="ruby-identifier">ind</span>).<span class="ruby-identifier">font</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-value str">&quot;@weight&quot;</span>),
         <span class="ruby-identifier">:fg</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">row</span>.<span class="ruby-identifier">format</span>(<span class="ruby-identifier">ind</span>).<span class="ruby-identifier">font</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-value str">&quot;@color&quot;</span>)
        }
        <span class="ruby-identifier">opts</span> = []
        <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">:ul</span>] <span class="ruby-operator">!=</span> <span class="ruby-identifier">:none</span>
          <span class="ruby-identifier">opts</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;underline&quot;</span>
        <span class="ruby-keyword kw">end</span> 
        <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">:so</span>] <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">false</span>
          <span class="ruby-identifier">opts</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;strike&quot;</span>
        <span class="ruby-keyword kw">end</span> 
        <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">:weight</span>] <span class="ruby-operator">&gt;</span> <span class="ruby-value">400</span>
          <span class="ruby-identifier">opts</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;bold&quot;</span>
        <span class="ruby-keyword kw">end</span>
        <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">:fg</span>] <span class="ruby-operator">!=</span> <span class="ruby-identifier">:text</span>
          <span class="ruby-identifier">opts</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;fore:&quot;</span><span class="ruby-operator">+</span><span class="ruby-identifier">hash</span>[<span class="ruby-identifier">:fg</span>].<span class="ruby-identifier">to_s</span>
        <span class="ruby-keyword kw">end</span>
        <span class="ruby-identifier">t</span>.<span class="ruby-identifier">color_xy</span>(<span class="ruby-identifier">i</span>,<span class="ruby-identifier">ind</span>,<span class="ruby-operator">*</span><span class="ruby-identifier">opts</span>)
        <span class="ruby-identifier">len</span>[<span class="ruby-identifier">ind</span>] = <span class="ruby-identifier">str</span>.<span class="ruby-identifier">length</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">str</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">len</span>[<span class="ruby-identifier">ind</span>]
        <span class="ruby-identifier">t</span>.<span class="ruby-identifier">fill_xy</span>(<span class="ruby-identifier">str</span>,<span class="ruby-identifier">i</span>,<span class="ruby-identifier">ind</span>)
      }
    }
    <span class="ruby-identifier">rbook</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">t</span>
  }
  [<span class="ruby-identifier">rbook</span>,<span class="ruby-identifier">book</span>]
 <span class="ruby-keyword kw">end</span></pre>
</body>
</html>